<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>分配网点</title>
<script type="text/javascript">
<%--存数数组--%>
var array = new Array();
<%--通函--%>
var _$ = function(id){return document.getElementById(id);};
var _clear = function(id){_$(id).value="";};
<%--初始化信息--%>
var _myinit = function(){
	var content = "";
	for(var i=0;i<array.length;i++){
		var obj = eval('(' + array[i] + ')');
		content += "<tr><td class='center' style='width: 85px;'>"+i+"</td>";
		content += "<td class='center' style='width: 85px;'>"+obj.order_weight+"公斤</td>";
		content += "<td class='center' style='width: 85px;'>"+obj.order_tiji+"</td>";
		content += "<td class='center' style='width: 173px;'>"+obj.qrCode+"</td>";
		content += "<td class='center' style='width: 85px;'>"+obj.order_price+"</td>";
		content += "<td class='center' style='width: 85px;'><em onclick='_delete(\""+i+"\")'>删除</em></td>";
		content += "<td class='center' style='width: 85px;'><em onclick='_edit(\""+i+"\")'>修改<em></td></tr>";
	}
	_$("tbody_table").innerHTML=content;
};
<%--页面初始化时重量输入框获取按钮并初始化信息--%>
$(function(){
	_$("order_weight").focus();
});
<%--监控重量输入框确定事件--%>
var _order_weight = function(e){
	var event = e || window.event;
	if(event.keyCode==13){
		_$("order_weight").readOnly = true;
		_$("order_qrCode").focus();
	}
};
<%--重新录入--%>
var _reset = function(){
	_$("order_weight").readOnly = false;
	_$("order_weight").value = "";
	_$("order_weight").focus();
	_$("order_tiji").value="";
	_$("order_qrCode").value="";
};
<%--删除选项--%>
var _delete = function(id){
	var ay = new Array();
	var length = 0;
	for(var i=0;i<array.length;i++){
		if(i!=id){
			ay[length] = array[i];
			length ++;
		}
	}
	array = ay;
	_myinit();
	_$("order_weight").readOnly = false;
	_$("order_weight").focus();
};
<%--编辑--%>
var _edit = function(id){
	var obj = eval('(' + array[id] + ')');
	_$("order_weight").readOnly = false;
	_$("order_weight").value = obj.order_weight;
	_$("order_weight").focus();
	_$("order_tiji").value=obj.order_tiji;
	_$("order_qrCode").value=obj.qrCode;
	_delete(id);
};
<%--监控二维码输入框确定事件--%>
var _order_qrcode = function(e){
	var event = e || window.event;
	if(event.keyCode==13){
		var _weight = $.trim(_$("order_weight").value);
		var _tiji = $.trim(_$("order_tiji").value);
		if(_tiji==null || _tiji==""){
			_tiji = 0;
		}
		var _qrcode = $.trim(_$("order_qrCode").value);
		if(_qrcode==""||_qrcode==null){
			alert("请输入二维码");
			return;
		}
		if(_weight==""){
			alert("重量不能为空");
			return;
		}
		var _price = "";
		var _weight_init  = Math.ceil(_weight);
		var price = 4 + (_weight_init - 1);
		<%--
		if(_weight_init<11){price = 4 + (_weight_init - 1);
		}else if(_weight_init<31){price = 15 + (_weight_init - 10) * 5;
		}else{price = 100 + (_weight_init - 30) * 10;}--%>
		var item = "{\"order_weight\":\""+_weight+"\",\"order_tiji\":\""+_tiji+"\",\"qrCode\":\""+_qrcode+"\",\"order_price\":\""+price+"\"}";
		array[array.length] = item;
		_myinit();
		_$("order_weight").readOnly = false;
		_$("order_weight").value = "";
		_$("order_weight").focus();
		_$("order_tiji").value="";
		_$("order_qrCode").value="";
	}
};
var _reg = function(){
	var json="["+array+"]";
	$.ajax({
        type: 'post',
        url:'<%=basePath%>dealSameCityOrders',
		data : {
			json : json
		},
		success : function(data) {
			var returnjson=eval('('+data+')');
			if(returnjson.success)
			{
				
				alertMsg.correct("处理成功！");
				array = new Array();
				_myinit();
				_reset();
			}else{
				alertMsg.correct("处理失败！");
			}
		}
		});
};
</script>
</head>
<body>
	<div class="pageContent">
		<div class="pageFormContent" layoutH="56">
			<table class="table">
				<thead>
					<tr>
						<th width="100" align="center">id</th>
						<th width="100" align="center">重量</th>
						<th width="100" align="center">体积</th>
						<th width="200" align="center">二维码</th>
						<th width="100" align="center">金额</th>
						<th width="100" align="center">删除</th>
						<th width="100" align="center">修改</th>
					</tr>
				</thead>
				<tbody id="tbody_table"></tbody>
			</table>
			<br> <br> <br> <br>
			<table>
				<tr>
					<td>重量：</td>
					<td><input type="text" id="order_weight" name="weight" style="width: 100px;" onkeyup="_order_weight(event)" /></td>
					<td>体积：</td>
					<td><input type="text" id="order_tiji" name="tiji" style="width: 100px;" /></td>
					<td>二维码：</td>
					<td><input type="text" id="order_qrCode" name="qrCode" style="width: 100px;" onkeyup="_order_qrcode(event)" /></td>
					<td><input type="button" value="重新录入" onclick="_reset()"/></td>
				</tr>
			</table>
		</div>
		<input type="button" value="提交" onclick="_reg()"/>
	</div>
	
</body>
</html>
